<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/6/25 16:31
 * Modified Time: 2019/6/25 16:31
 * Version: 2.0
 */

namespace App\Modules\System\Repositories;


use App\Models\StoreResource;
use App\Modules\Store\Criterias\GetStoreViedoCriteria;
use Flower\Core\Repository\Eloquent\BaseRepository;

class StoreResourceRepository extends BaseRepository
{
    public function model()
    {
        return StoreResource::class;
    }

    /**
     * 创建资源
     * @param $store_id
     * @param $resource
     * @param $type
     */
    public function createResource($store_id,$resource,$type)
    {
        $data = [
            'store_id' => $store_id,
            'resource' => $resource,
            'type' => $type
        ];
        $this->create($data);
    }

    public function deleteStoreAllResource($store_id)
    {
        return $this->deleteWhere([['store_id','=',$store_id]]);
    }

    public function getStorePicture($store_id)
    {
        return $this->model->leftJoin('picture','store_resource.resource','picture.id')->where('type',1)->where('store_id',$store_id)->get();
    }

	/**
	 * 查询店铺资源数量
	 * @param $store_id
	 * @param int $type
	 * @return mixed
	 */
    public function getStoreResourceCount($store_id,$type=1)
    {
        return $this->model->where('store_id','=',$store_id)
	        ->when(isset($type),function ($v)use($type){
	        	$v->where(['type'=>$type]);
	        })
	        ->count();
    }
}